
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBMineProvider/YBMineUserProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';
import 'package:fluwx/fluwx.dart' as fluwx;

class YBAccountAndBandingPage extends StatefulWidget {
  @override
  _YBAccountAndBandingPageState createState() => _YBAccountAndBandingPageState();
}

class _YBAccountAndBandingPageState extends State<YBAccountAndBandingPage> {



  @override
  Widget build(BuildContext context) {

    fluwx.weChatResponseEventHandler.distinct((a,b) => a == b).listen((event) {
      if(event is fluwx.WeChatAuthResponse){
        print('object------${event.code}----');
        if (event.code != null) {
           setBandingWeChat(event.code);
        }
      }
    });

    return Container(
      child: Scaffold(
        appBar: AppBar(
           elevation: 0,
           title: Text(
             YBChineseText.mineSetBindingTitle,
             style: YBTextStyle.TextStyle30313320Medium,
           ),
        ),
        body: ChangeNotifierProvider(
            create: (context) => YBMineUserProvider()..getUserInfoData(),
            child: Consumer<YBMineUserProvider>(
                builder:(context,userInfoData,child){

                  print('object---${userInfoData.mineUserInfoModel.unionid}');
                   bool isBinding = false;
                  if (!ObjectUtil.isEmptyString(userInfoData.mineUserInfoModel.unionid)){
                      isBinding = true;
                  }


                  return SingleChildScrollView(
                    child: Column(
                      children: [
                        Container(
                          child: InkWell(
                            child: Container(
                              color: YBColor.white,
                              height: YBTextStyle.adapterSize58,
                              child: Padding(
                                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                child: Row(
                                  children: [
                                    Container(
                                        alignment: Alignment.centerLeft,
                                        child: Text(YBChineseText.mineXiuGaibingdingTitle,style: YBTextStyle.findFaXiantText,)
                                    ),
                                    Spacer(),
                                    Container(
                                        alignment: Alignment.centerRight,
                                        child: Text(userInfoData.mineUserInfoModel.customerPhone??"",style: YBTextStyle.TextStyle99999912,)
                                    ),
                                    Container(
                                      width: 10,
                                    ),
                                    Container(
                                      child: Image.asset(YBImageStyle.getImagePath("findIconArrowRight"),width: YBTextStyle.adapterSize6,height: YBTextStyle.adapterSize10,),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            onTap: (){
                              YBApplication.router.navigateTo(context, '/mine/mineSettingPage/mineSettingXiuGaiPhoneYanMaPage?phoneN=${userInfoData.mineUserInfoModel.customerPhone}');
                            },
                          ),
                        ),
                        Container(
                          child: InkWell(
                            child: Container(
                              color: YBColor.white,
                              height: 58,
                              child: Padding(
                                padding: EdgeInsets.only(left: 20,right: 20),
                                child: Row(
                                  children: [
                                    Container(
                                        alignment: Alignment.centerLeft,
                                        child: Text("修改密码",style: YBTextStyle.findFaXiantText,)
                                    ),
                                    Spacer(),

                                    Container(
                                      child: Image.asset(YBImageStyle.getImagePath("findIconArrowRight"),width: 6,height: 10,),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            onTap: (){
                              YBApplication.router.navigateTo(context, '/mine/mineSettingPage/mineSettingXiuGaiMiMaPage?phoneN=${userInfoData.mineUserInfoModel.customerPhone}');
                            },
                          ),
                        ),
                        Container(
                          height: 8,
                        ),
                        Container(
                          child: InkWell(
                            child: Container(
                              color: YBColor.white,
                              height: 58,
                              child: Padding(
                                padding: EdgeInsets.only(left: 20,right: 20),
                                child: Row(
                                  children: [
                                    Container(
                                        alignment: Alignment.centerLeft,
                                        child: Text("绑定微信",style: YBTextStyle.findFaXiantText,)
                                    ),
                                    Spacer(),
                                    Container(
                                        alignment: Alignment.centerLeft,
                                        child: isBinding?Text("绑定",style: YBTextStyle.TextStyle99999912,):Text("未绑定",style: YBTextStyle.TextStyle99999912,)
                                    ),
                                    Container(
                                      width: 10,
                                    ),
                                    Container(
                                      child: Image.asset(YBImageStyle.getImagePath("findIconArrowRight"),width: 6,height: 10,),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            onTap: isBinding? null: (){
                              fluwx.sendWeChatAuth(scope: "snsapi_userinfo",state: "xingge_benlaitongji").then((value){
                                print("----object---$value---");
                              });
                            },
                          ),
                        ),
                      ],
                    ),
                  );
                }
            ),
        ),
      ),
    );
  }

  void setBandingWeChat(String code) {
    YBMineNetWork.mineSettingBandingWeChatData({
      "sysCode":"xg_youbang",
      "code":code,
    },success: (data){
      print('----$data----');
    },fail: (error){
      print('----$error----');
    });
  }

}
